﻿using ComponentFactory.Krypton.Toolkit;
using SRB.Tg.DrawingStandard;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SRB.Tg.Cad
{
    public partial class GJInfoForm : KryptonForm
    {
        SubstructureType _type = SubstructureType.Pile;
        double _scale=1;
        DataRow _row;
        private  MainForms _parent;
        bool isAdd = false;
        public DataRow mySelectRow;
        public GJInfoForm()
        {
            InitializeComponent();
        }

        public GJInfoForm(MainForms frm, SubstructureType type)
        {
            InitializeComponent();
            _parent = frm;
            _type = type;
            InitGJInfo(type);
            isAdd = true;
        }
        public GJInfoForm(MainForms frm,SubstructureType type, DataRow row, double scale)
        {
            InitializeComponent();
            _parent = frm;
            _type = type;
            _scale = scale;
            _row = row;
            InitGJInfo(type,row);
            isAdd = false;
        }

        private void InitGJInfo(SubstructureType type, DataRow row)
        {
            switch (type)
            {
                case SubstructureType.PileCap:
                    PileCapManagerForm frmPileCap = PileCapManagerForm.getInstance(row, _scale);
                    frmPileCap.TopLevel = false;
                    frmPileCap.Dock = DockStyle.Fill;
                    frmPileCap.Activate();
                    frmPileCap.FormBorderStyle = FormBorderStyle.None;                 
                    gjPanel.Controls.Add(frmPileCap);
                    frmPileCap.Show();
                    break;
                case SubstructureType.Pile:
                    PileManagerForm frmPile =PileManagerForm.getInstance(row, _scale);
                    frmPile.TopLevel = false;
                    frmPile.Dock = DockStyle.Fill;
                    frmPile.Activate();
                    frmPile.FormBorderStyle = FormBorderStyle.None;
                    gjPanel.Controls.Add(frmPile);
                    frmPile.Show();
                    break;
                case SubstructureType.Plinth:
                    PlinthInfoForm frmPlinth = PlinthInfoForm.getInstance(row, _scale);
                    frmPlinth.TopLevel = false;
                    frmPlinth.Dock = DockStyle.Fill;
                    frmPlinth.Activate();
                    frmPlinth.FormBorderStyle = FormBorderStyle.None;
                    gjPanel.Controls.Add(frmPlinth);
                    frmPlinth.Show();
                    break;
            }
         
        }
        private void InitGJInfo(SubstructureType type)
        {
            gjPanel.Controls.Clear();
            switch (type)
            {
                case SubstructureType.PileCap:
                    PileCapManagerForm frmPileCap =PileCapManagerForm.getInstance(true);
                    frmPileCap.TopLevel = false;
                    frmPileCap.Dock = DockStyle.Fill;
                    frmPileCap.Activate();
                    frmPileCap.FormBorderStyle = FormBorderStyle.None;
                    gjPanel.Controls.Add(frmPileCap);
                    frmPileCap.Show();
                    break;
                case SubstructureType.Pile:       
                    PileManagerForm frmPile =PileManagerForm.getInstance(true);
                    frmPile.TopLevel = false;
                    frmPile.Dock = DockStyle.Fill;
                    frmPile.Activate();
                    frmPile.FormBorderStyle = FormBorderStyle.None;
                    gjPanel.Controls.Add(frmPile);
                    frmPile.Show();
                    break;
                case SubstructureType.Plinth:
                    //PlinthInfoForm frmPlinth =new PlinthInfoForm();
                    //frmPlinth.TopLevel = false;
                    //frmPlinth.Dock = DockStyle.Fill;
                    //frmPlinth.Activate();
                    //frmPlinth.FormBorderStyle = FormBorderStyle.None;
                    //gjPanel.Controls.Add(frmPlinth);
                    //frmPlinth.Show();
                    break;
            }

        }
        #region 构件参数修改委托重新加载
        public delegate void Send_GJConfirm_To_Form_Main(DataRow mySelectRow,double scale);
        public event Send_GJConfirm_To_Form_Main Send_GJConfirm;
        public delegate void Send_GJConfirmBefore_To_Form_Main();
        public event Send_GJConfirmBefore_To_Form_Main Send_GJConfirmBefore;
        #endregion
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                Send_GJConfirmBefore();

                SingleCAD.getInstance(_parent).SetPageModel();
                Tools.ClearDatabase();
                try
                {
                    if (isAdd)
                    {
                        switch (_type)
                        {
                            case SubstructureType.PileCap:
                                PileCapManagerForm.getInstance().SaveAdd();
                                mySelectRow = PileCapManagerForm.getInstance().myrow;                              
                                break;
                            case SubstructureType.Pile:
                                PileManagerForm.getInstance().SaveAdd();
                                mySelectRow = PileManagerForm.getInstance().myrow;                             
                                break;
                            case SubstructureType.Plinth:
                                //PlinthInfoForm.getInstance(_row, _scale).SavModify();
                                //TeighaBase.getInstance(_parent).SaveTempDwg("Plinth", "Plinth" + DateTime.Now.ToString("yyyyMMddHHmmss"));
                                break;
                        }
                    }
                    else
                    {
                        switch (_type)
                        {
                            case SubstructureType.PileCap:
                                PileCapManagerForm.getInstance(_row, _scale, true).SavModify();
                                mySelectRow = PileCapManagerForm.getInstance(_row, _scale, true).myrow;
                                TeighaBase.getInstance(_parent).SaveTempDwg("PileCap", "PileCap" + DateTime.Now.ToString("yyyyMMddHHmmss"));
                                break;
                            case SubstructureType.Pile:
                                PileManagerForm.getInstance(_row, _scale,true).SavModify();
                                mySelectRow = PileManagerForm.getInstance(_row, _scale, true).myrow;
                                TeighaBase.getInstance(_parent).SaveTempDwg("Pile", "Pile" + DateTime.Now.ToString("yyyyMMddHHmmss"));
                                break;
                            case SubstructureType.Plinth:
                                //PlinthInfoForm.getInstance(_row, _scale).SavModify();
                                //TeighaBase.getInstance(_parent).SaveTempDwg("Plinth", "Plinth" + DateTime.Now.ToString("yyyyMMddHHmmss"));
                                break;
                        }
                    }
                }
                catch (Exception ex)
                {

                }
                Send_GJConfirm(mySelectRow, _scale);
            }
            catch (Exception ex)
            {

            }
        }

    }
}
